// Decompiled by DJ v3.11.11.95 Copyright 2009 Atanas Neshkov  Date: 1/30/2010 10:57:39 PM
// Home Page: http://members.fortunecity.com/neshkov/dj.html  http://www.neshkov.com/dj.html - Check often for new version!
// Decompiler options: packimports(3) 
// Source File Name:   MazeFrame.java

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class MazeFrame extends JFrame
    implements ActionListener
{
    public class MazeSolutionThread extends Thread
    {

        public void run()
        {
            disableButtons();
            mazeDisplayPanel.setAnimateSolution(animateSolution.isSelected());
            MazeSolution mazesolution = solver.solveMaze(maze, mazeDisplayPanel);
            mazeDisplayPanel.setCurrentSolution(mazesolution);
            enableButtons();
        }

        private MazeSolver solver;
        private Maze maze;

        public MazeSolutionThread(MazeSolver mazesolver, Maze maze1)
        {
            solver = mazesolver;
            maze = maze1;
        }
    }

    public class MazeGenerationThread extends Thread
    {

        public void run()
        {
            mazeDisplayPanel.setCurrentSolution(null);
            disableButtons();
            mazeDisplayPanel.setAnimateGeneration(animateGeneration.isSelected());
            byte byte0;
            if(smallMazeButton.isSelected())
                byte0 = 10;
            else
            if(mediumMazeButton.isSelected())
                byte0 = 20;
            else
                byte0 = 30;
            Maze maze = generator.generateMaze(byte0, byte0, mazeDisplayPanel);
            mazeDisplayPanel.setCurrentMaze(maze);
            enableButtons();
        }

        private MazeGenerator generator;

        public MazeGenerationThread(MazeGenerator mazegenerator)
        {
            generator = mazegenerator;
        }
    }


    public MazeFrame()
    {
        super("ICS 23 Project #1: Dark at the End of the Tunnel");
        setSize(700, 500);
        setResizable(false);
        buildUI();
        addWindowListener(new WindowAdapter() {

            public void windowClosing(WindowEvent windowevent)
            {
                System.exit(0);
            }

        }
);
        setDefaultCloseOperation(0);
    }

    public void buildUI()
    {
        GridBagLayout gridbaglayout = new GridBagLayout();
        getContentPane().setLayout(gridbaglayout);
        mazeDisplayPanel = new MazeDisplayPanel();
        getContentPane().add(mazeDisplayPanel);
        gridbaglayout.addLayoutComponent(mazeDisplayPanel, new GridBagConstraints(0, 0, 1, 2, 1.0D, 1.0D, 17, 1, new Insets(5, 5, 5, 5), 0, 0));
        JPanel jpanel = new JPanel();
        GridBagLayout gridbaglayout1 = new GridBagLayout();
        jpanel.setLayout(gridbaglayout1);
        getContentPane().add(jpanel);
        gridbaglayout.addLayoutComponent(jpanel, new GridBagConstraints(1, 0, 1, 1, 0.0D, 1.0D, 13, 0, new Insets(5, 5, 5, 5), 0, 0));
        useStudentGeneratorButton = new JRadioButton("Use my generator", false);
        useStudentGeneratorButton.addActionListener(this);
        jpanel.add(useStudentGeneratorButton);
        gridbaglayout1.addLayoutComponent(useStudentGeneratorButton, new GridBagConstraints(0, 0, 1, 1, 0.0D, 0.0D, 17, 0, new Insets(5, 5, 0, 5), 0, 0));
        useProvidedGeneratorButton = new JRadioButton("Use provided generator", true);
        useProvidedGeneratorButton.addActionListener(this);
        jpanel.add(useProvidedGeneratorButton);
        gridbaglayout1.addLayoutComponent(useProvidedGeneratorButton, new GridBagConstraints(0, 1, 1, 1, 0.0D, 0.0D, 17, 0, new Insets(5, 5, 10, 5), 0, 0));
        smallMazeButton = new JRadioButton("Small (10x10)", true);
        smallMazeButton.addActionListener(this);
        jpanel.add(smallMazeButton);
        gridbaglayout1.addLayoutComponent(smallMazeButton, new GridBagConstraints(0, 2, 1, 1, 0.0D, 0.0D, 17, 0, new Insets(5, 5, 0, 5), 0, 0));
        mediumMazeButton = new JRadioButton("Medium (20x20)", false);
        mediumMazeButton.addActionListener(this);
        jpanel.add(mediumMazeButton);
        gridbaglayout1.addLayoutComponent(mediumMazeButton, new GridBagConstraints(0, 3, 1, 1, 0.0D, 0.0D, 17, 0, new Insets(5, 5, 0, 5), 0, 0));
        largeMazeButton = new JRadioButton("Large (30x30)", false);
        largeMazeButton.addActionListener(this);
        jpanel.add(largeMazeButton);
        gridbaglayout1.addLayoutComponent(largeMazeButton, new GridBagConstraints(0, 4, 1, 1, 0.0D, 0.0D, 17, 0, new Insets(5, 5, 10, 5), 0, 0));
        animateGeneration = new JCheckBox("Animate", false);
        jpanel.add(animateGeneration);
        gridbaglayout1.addLayoutComponent(animateGeneration, new GridBagConstraints(0, 5, 1, 1, 0.0D, 0.0D, 17, 0, new Insets(5, 5, 0, 5), 0, 0));
        generateMazeButton = new JButton("Generate Maze");
        generateMazeButton.addActionListener(this);
        jpanel.add(generateMazeButton);
        gridbaglayout1.addLayoutComponent(generateMazeButton, new GridBagConstraints(0, 6, 1, 1, 0.0D, 0.0D, 15, 0, new Insets(5, 5, 5, 5), 0, 0));
        JPanel jpanel1 = new JPanel();
        GridBagLayout gridbaglayout2 = new GridBagLayout();
        jpanel1.setLayout(gridbaglayout2);
        getContentPane().add(jpanel1);
        gridbaglayout.addLayoutComponent(jpanel1, new GridBagConstraints(1, 1, 1, 1, 0.0D, 1.0D, 13, 0, new Insets(5, 5, 5, 5), 0, 0));
        useStudentSolverButton = new JRadioButton("Use my solver", false);
        useStudentSolverButton.addActionListener(this);
        jpanel1.add(useStudentSolverButton);
        gridbaglayout2.addLayoutComponent(useStudentSolverButton, new GridBagConstraints(0, 0, 1, 1, 0.0D, 0.0D, 17, 0, new Insets(5, 5, 0, 5), 0, 0));
        useProvidedSolverButton = new JRadioButton("Use provided solver", true);
        useProvidedSolverButton.addActionListener(this);
        jpanel1.add(useProvidedSolverButton);
        gridbaglayout2.addLayoutComponent(useProvidedSolverButton, new GridBagConstraints(0, 1, 1, 1, 0.0D, 0.0D, 17, 0, new Insets(5, 5, 0, 5), 0, 0));
        animateSolution = new JCheckBox("Animate");
        jpanel1.add(animateSolution);
        gridbaglayout2.addLayoutComponent(animateSolution, new GridBagConstraints(0, 2, 1, 1, 0.0D, 0.0D, 17, 0, new Insets(5, 5, 0, 5), 0, 0));
        solveMazeButton = new JButton("Solve Maze");
        solveMazeButton.addActionListener(this);
        jpanel1.add(solveMazeButton);
        gridbaglayout2.addLayoutComponent(solveMazeButton, new GridBagConstraints(0, 3, 1, 1, 0.0D, 0.0D, 15, 0, new Insets(5, 5, 5, 5), 0, 0));
        enableGeneratorButtons();
        disableSolverButtons();
    }

    private void disableButtons()
    {
        disableGeneratorButtons();
        disableSolverButtons();
    }

    private void disableGeneratorButtons()
    {
        setGeneratorButtonEnabledStates(false);
    }

    private void disableSolverButtons()
    {
        setSolverButtonEnabledStates(false);
    }

    private void enableButtons()
    {
        enableGeneratorButtons();
        enableSolverButtons();
    }

    private void enableGeneratorButtons()
    {
        setGeneratorButtonEnabledStates(true);
    }

    private void enableSolverButtons()
    {
        setSolverButtonEnabledStates(true);
    }

    private void setGeneratorButtonEnabledStates(boolean flag)
    {
        useStudentGeneratorButton.setEnabled(flag);
        useProvidedGeneratorButton.setEnabled(flag);
        smallMazeButton.setEnabled(flag);
        mediumMazeButton.setEnabled(flag);
        largeMazeButton.setEnabled(flag);
        animateGeneration.setEnabled(flag);
        generateMazeButton.setEnabled(flag);
    }

    private void setSolverButtonEnabledStates(boolean flag)
    {
        useStudentSolverButton.setEnabled(flag);
        useProvidedSolverButton.setEnabled(flag);
        animateSolution.setEnabled(flag);
        solveMazeButton.setEnabled(flag);
    }

    private void generateMaze()
    {
        Object obj = null;
        if(useStudentGeneratorButton.isSelected())
            obj = new StudentMazeGenerator();
        else
            obj = new UFMazeGenerator();
        MazeGenerationThread mazegenerationthread = new MazeGenerationThread(((MazeGenerator) (obj)));
        mazegenerationthread.start();
    }

    private void solveMaze()
    {
        Object obj = null;
        if(useStudentSolverButton.isSelected())
            obj = new StudentMazeSolver();
        else
            obj = new DFMazeSolver();
        MazeSolutionThread mazesolutionthread = new MazeSolutionThread(((MazeSolver) (obj)), mazeDisplayPanel.getCurrentMaze());
        mazesolutionthread.start();
    }

    public void actionPerformed(ActionEvent actionevent)
    {
        Object obj = actionevent.getSource();
        if(obj == useStudentGeneratorButton)
        {
            useStudentGeneratorButton.setSelected(true);
            useProvidedGeneratorButton.setSelected(false);
        } else
        if(obj == useProvidedGeneratorButton)
        {
            useProvidedGeneratorButton.setSelected(true);
            useStudentGeneratorButton.setSelected(false);
        } else
        if(obj == smallMazeButton)
        {
            smallMazeButton.setSelected(true);
            mediumMazeButton.setSelected(false);
            largeMazeButton.setSelected(false);
        } else
        if(obj == mediumMazeButton)
        {
            smallMazeButton.setSelected(false);
            mediumMazeButton.setSelected(true);
            largeMazeButton.setSelected(false);
        } else
        if(obj == largeMazeButton)
        {
            smallMazeButton.setSelected(false);
            mediumMazeButton.setSelected(false);
            largeMazeButton.setSelected(true);
        } else
        if(obj == generateMazeButton)
            generateMaze();
        else
        if(obj == useStudentSolverButton)
        {
            useStudentSolverButton.setSelected(true);
            useProvidedSolverButton.setSelected(false);
        } else
        if(obj == useProvidedSolverButton)
        {
            useProvidedSolverButton.setSelected(true);
            useStudentSolverButton.setSelected(false);
        } else
        if(obj == solveMazeButton)
            solveMaze();
    }

    private MazeDisplayPanel mazeDisplayPanel;
    private JRadioButton useStudentGeneratorButton;
    private JRadioButton useProvidedGeneratorButton;
    private JRadioButton smallMazeButton;
    private JRadioButton mediumMazeButton;
    private JRadioButton largeMazeButton;
    private JCheckBox animateGeneration;
    private JButton generateMazeButton;
    private JRadioButton useStudentSolverButton;
    private JRadioButton useProvidedSolverButton;
    private JCheckBox animateSolution;
    private JButton solveMazeButton;







}
